package com.ay.weixin.fdc.admin.category.domain;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.lizar.json.JList;
import org.lizar.json.JObject;

public class Category {
	
	private int id;
	
	private String name;
	
	private int parent_id;
	
	private int pos;
	
	private int display;
	
	private String groups;
	
	private List<Category> clist;
	
	public JObject toJSon(){
		JObject obj=new JObject();
		obj.put("id", this.id);
		obj.put("name",this.name);
		obj.put("pos",this.pos);
		obj.put("display",this.display);
		obj.put("groups",this.groups);
		obj.put("parent_id",this.parent_id);
		JList list=new JList();
		obj.put("subs",list);
		if(clist!=null){
			Iterator<Category> itr=clist.iterator();
			for(;itr.hasNext();){
				list.add(itr.next().toJSon());
			}
		}
		return obj;
	}
	
	public void setSubCategory(Category c){
		if(clist==null){
			clist=new LinkedList<Category>();
		}
		clist.add(c);
	}
	
	
	public List<Category> getSubs(){
		return clist;
	}
	
	public void clearSubs(){
		if(clist!=null){
			clist.clear();
			clist=null;
		}
	}
	

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getParent_id() {
		return parent_id;
	}

	public void setParent_id(int parent_id) {
		this.parent_id = parent_id;
	}

	public int getPos() {
		return pos;
	}

	public void setPos(int pos) {
		this.pos = pos;
	}

	public int getDisplay() {
		return display;
	}

	public void setDisplay(int display) {
		this.display = display;
	}


	public String getGroups() {
		return groups;
	}


	public void setGroups(String groups) {
		this.groups = groups;
	}


}
